package org.jxf.gps.jt808.server;

import java.net.InetSocketAddress;
import java.util.concurrent.Executors;

import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory;
import org.jxf.gps.jt808.nettysample.test.UDPChannelPipelineFactory;

public class UDPServer {
    
    public final int PORT;
    public UDPServer(int port){
        PORT=port;
    }
    private ConnectionlessBootstrap  bootstrap;
    void start(){
        //init the bootstrap
    	
        bootstrap=new ConnectionlessBootstrap(new NioDatagramChannelFactory(Executors.newCachedThreadPool()));
        bootstrap.setPipelineFactory(new UDPChannelPipelineFactory());
        bootstrap.bind(new InetSocketAddress(PORT));
        System.out.println("server start at:"+":"+PORT);
    }
    
    public static void main(String[] args) {
        /*
         * 获取一个可用的端口号
         */
        //int port= new ScanGetPort().getPot(8080);
        new UDPServer(9090).start();
    }
    
}